﻿#define _CRT_SECURE_NO_WARNINGS  1
//一定要动手，例子不管多么简单，建议至少自己手敲一遍看看是否理解了里头的细枝末节。
//一定要学会思考，思考为什么要这样，而不是那样。还要举一反三地思考
#include<iostream>
#include<string>
#include<vector>
using namespace std;
template<class T>
void mytest( T& x,  T& y)
{
	T tem = x;
	x = y;
	y = tem;
}
template<class x,class y>
void func(const x& a, const y& b)
{
	cout << a << b << endl;
}
template <class T2>
T2 Add(T2 right, T2 lift)
{
	return left + right;
}
template<class T3>
T3* f(int n)
{
	T3* p = new T3[n];
	return  p;
}
//创建一个例模板
//template <class T>
//class stack {
//private:
//	int _capacity;
//	T* _a;
//	int _size;
//
//public:
//	stack(int capacity = 4)
//	{
//		cout << "构造函数调用" << endl;
//
//		this->_a = new T[capacity];
//		this->_capacity = capacity;
//		this->_size = 0;
//	}
//	~stack()
//	{
//		cout << "析构函数调用" << endl;
//
//		delete[] _a;
//		_a = nullptr;
//		this->_size = 0;
//		this->_capacity = 0;
//	}
//};
template<class T>
class Stack
{
public:
	Stack(int capacity = 4)
	{
		cout << "Stack(int capacity = 4)" << endl;

		_a = new T[capacity];
		_top = 0;
		_capacity = capacity;
	}

	~Stack()
	{
		cout << "~Stack()" << endl;

		delete[] _a;
		_a = nullptr;
		_top = 0;
		_capacity = 0;
	}
private:
	T* _a;
	int  _top;
	int  _capacity;
};
int main()
{
	//推演实例化
	//函数参数传递，推出函数参数模板类型，生成对应函数
	func(1, 2);
	func(1.1, 1.3);
	func(1.1, 3);
	//显示实例化
	double* g = f<double>(10);
	//例模板显示实例化
	//stack<int> st1;  // int
	//stack<double> st2;  // double
	Stack<int> st1;  // int
	Stack<double> st2;  // double
	system("pause");
	return 0;
}